//
//  BIZConsultQuestionCell.m
//  biz
//
//  Created by 边文辉 on 2017/3/17.
//  Copyright © 2017年 jieshuibao. All rights reserved.
//

#import "BIZConsultQuestionCell.h"
#import "BIZConsultQModel.h"
#import "HZPhotoGroup.h"


@interface BIZConsultQuestionCell ()
@property (weak, nonatomic) IBOutlet UIImageView *headImageView;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *contentLabel;
@property (weak, nonatomic) IBOutlet UILabel *dateLable;
@property (weak, nonatomic) IBOutlet HZPhotoGroup *photoGroup;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *photoGroupHeight;
@property (weak, nonatomic) IBOutlet UIView *redView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *reminderLabelTopLayout;
@property (weak, nonatomic) IBOutlet UILabel *reminderLabel;


@end

@implementation BIZConsultQuestionCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    _nameLabel.text = [BIZUserModel shareUser].name;
}

- (void)setModel:(BIZConsultQModel *)model
{
    _model = model;
    
    _nameLabel.text = [BIZUserModel shareUser].name;
    _contentLabel.text = _model.content;
    _dateLable.text = [NSDate stringFromTimestamp:_model.updateTime];
    [SDWebImageTool imageView:self.headImageView imageName:[BIZUserModel shareUser].detailModel.headImg placeHolder:@"default-head" showProgress:NO];
    
    if ([_model.status integerValue] == 2) {
        self.redView.hidden = NO;
    } else {
        self.redView.hidden = YES;
    }
    
}

- (void)setIsHistoryList:(BOOL)isHistoryList
{
    _isHistoryList = isHistoryList;
    if (isHistoryList) {
        self.reminderLabelTopLayout.constant = 0;
        self.reminderLabel.text = @"";
        self.contentLabel.numberOfLines = 3;
    } else {
       self.contentLabel.numberOfLines = 0;
    }
}

- (void)setShowImage:(BIZConsultQuestionCellShowImageType)showImage
{
    _showImage = showImage;
    [self imageShow];
}

- (void)imageShow
{
    if (!_model || _showImage == BIZConsultQuestionCellShowImageTypeNone || !self.model.imgs || !self.model.imgs.length)
    {
        _photoGroup.photoItemArray = @[];
        [_photoGroup setHeight:0];
        _photoGroupHeight.constant = 0;
        return;
    };
    
    NSMutableArray *images = [@[] mutableCopy];
    if (_showImage == BIZConsultQuestionCellShowImageTypeShow) {

        NSArray *arr = [_model.imgs componentsSeparatedByString:@","];
        [arr enumerateObjectsUsingBlock:^(NSString *obj, NSUInteger idx, BOOL * _Nonnull stop) {
            [images addObject:[NSString stringWithFormat:@"%@/%@/%@", kMainBaseUrl, kShowImage, obj]];
        }];
    }
    
    _photoGroup.photoItemArray = images;
    _photoGroupHeight.constant = _photoGroup.height;
    
}

- (void)layoutSubviews
{
    
}


@end
